function load_image(data) {
        for (var i = 0; i < data.info.length; i++) {
            var row = data.info[i];
            var str = '        <div class="item" data-w="' + row.width + '" data-h="' + row.height + '">\n' +
                '          <a href="/picture/single/?pid=' + row.id + '">\n' +
                '            <img src="' + row.url + '" alt="">\n' +
                '          </a>\n' +
                '          <div>\n' +
                '            <div class="counts hide-xs hide-sm ">\n' +
                '              <em data-href="" class="ajax"><i class="iconfont icon-changyongicon-" style="pointer-events: none;"></i>\n' +
                '                ' + row.click_num + '</em>\n' +
                '              <em data-href="" class="ajax"><i class="iconfont icon-icon_like"\n' +
                '                  style="pointer-events: none;"></i> ' + row.star_num + '</em>\n' +
                '              <em data-location=""><i class="iconfont icon-favorite"></i> ' + row.parise_num + '</em>\n' +
                '            </div>\n' +
                '            <a href=""></a>\n' +
                '          </div>\n' +
                '        </div>';
            // 异步加载
            $('.flex-images').append(str);
        }
        changeImage();
        $('.flex-images').flexImages({rowHeight: 275});
        // 显示点赞收藏数
        $(".item").hover(
            function (e) {
                e.currentTarget.children[1].style.opacity = 1;
            },
            function (j) {
                j.currentTarget.children[1].style.opacity = 0;
            });
        // 更新当前页数
        var cur_page = $('#page_num').text();
        $('#page_num').text(Number(cur_page) + 25);
    }

//检测用户是否已登录
function is_log() {
    $.get('/user/session_get/', function (data, status) {
    var jsonObj = JSON.parse(data);
    var code = jsonObj['status'];
    if (code == '200'){
        $('#login').css('display','none');
        $('#user').css('display','');
        $('#user').text(jsonObj['info']['name']);
        $('#user').attr("href", '/user/center/');
    }
});
}

//用户登录
function login() {
    $('#login').click(function () {
        var url = window.location.href;
        window.location.href = '/user/login/?url=' + url;
    });
}

$(function () {
    // 请求图片
    $.get('/picture/pictures/', {}, function (data) {
        data = JSON.parse(data);
        // 处理异常
        if (data.status == 200) {
            load_image(data)
        } else {}
    });

    // 加载更多
    $('.pure-button').click(function () {
        $.get('/picture/pictures/', {'num': $('#page_num').text()}, function (data) {
            data = JSON.parse(data);

            // 处理异常
            if (data.status == 200) {
                load_image(data)
            } else {}
        })
    });

    //登录
    is_log();
    login();
});